
import request from '@/utils/request.js';

//创建交换订单
export const createExchangeAPI = (data) => {
    return request({
        url: '/trade/createExchangeOrder',
        method: 'post',
        data,
    });
};
//检查是否有相同的订单
export const checkExchangeAPI = (buyerId, sellerId, goodsId) => {
    return request({
        url: '/trade/checkCanExchange',
        method: 'get',
        params: { buyerId, sellerId, goodsId },
    })
}
//获取交换订单列表
export const getExchangeListAPI = (buyerId) => {
    return request({
        url: '/trade/queryExchangeOrder',
        method: 'get',
        params: { buyerId},
    })
}
//取消交换订单
export const cancelExchangeAPI = (orderId) => {
    return request({
        url: '/trade/userCancelExchangeOrder',
        method: 'put',
      params: { orderId },
    })
    }
//查询地址
export const getAddressAPI = (userId) => {
    return request({
        url: '/trade/queryAddress',
        method: 'get',
        params: { userId },
    })
}
//根据收件信息id查询收件人地址
export const getAddressByIdAPI = (mailAddressId) => {
    return request({
        url: '/trade/queryAddressById',
        method: 'get',
        params: { mailAddressId },
    })
}
//创建交易订单
export const createTradeAPI = (data) => {
    return request({
        url: '/trade/createTradeOrder',
        method: 'post',
        data,
    })
}
//查询交易订单
export const getTradeListAPI = (userId) => {
    return request({
        url: '/trade/queryTradeOrder',
        method: 'get',
        params: { userId },
    })
}
//更新交易订单
export const updateTradeAPI = (orderId, status) => {
    return request({
        url: '/trade/updateTradeOrderStatus',
        method: 'put',
        params: { orderId, status },

    })
}

//支付
export const payAPI = (orderId,payPassword,price, userId) => {
    return request({
        url: '/trade/payTradeOrder',
        method: 'put',
        params: {  orderId,payPassword,price, userId },
    })
}
//查询我卖的商品
export const getMySellAPI = (userId) => {
    return request({
        url: '/trade/queryMyTrade',
        method: 'get',
        params: { userId },
    })
}

//查询我交换的商品
export const getMyExchangeAPI = (userId) => {
    return request({
        url: '/trade/queryMyExchange',
        method: 'get',
        params: { userId },
    })
}

//发货
export const sendAPI = (orderId,sellerAddressId,goodsId,nums) => {
    return request({
        url: '/trade/sendGoods',
        method: 'put',
        params: { orderId, sellerAddressId , goodsId,nums},
    })
}
//确认收货
export const receiveAPI = (orderId,goodsId,userId,nums) => {
    return request({
        url: '/trade/confirmReceive',
        method: 'put',
        params: { orderId , goodsId,userId,nums },
    })
}

//拒绝交换
export const refuseExchangeAPI = (orderId) => {
    return request({
        url: '/trade/refuseExchange',
        method: 'put',
        params: { orderId },
    })
}

//同意交换
export const agreeExchangeAPI = (data) => {
    return request({
        url: '/trade/agreeExchange',
        method: 'post',
        data
    })
}
